package org.alis.smallcc.designpatterns.structural.decorator;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 其次我们有一个抽象电脑
 * 
 * @author luochuan
 */
public abstract class AbstractComputer implements IComputer{
	
	/**
	 * 本电脑含有硬件
	 */
	private List<Hardware> hardwareList;
	
	public AbstractComputer() {
		hardwareList = new LinkedList<>();
		// 基础的电脑就只有一些简单的配置
		hardwareList.add(new IntelCpu());
		hardwareList.add(new DellDisplay());
		hardwareList.add(new KingstonMemery());
	}
	
	@Override
	public String desc() {
		return hardwareList.stream().map(Hardware::desc).collect(Collectors.joining(";","[","]"));
	}
	@Override
	public final Integer count() {
		return hardwareList.stream().mapToInt(Hardware::place).sum();
	}
	
	@Override
	public final IComputer addHardware(Hardware hardware) {
		this.hardwareList.add(hardware);
		return this;
	}
	
}
